$(document).ready(
		function() {
			$("#password-input").hide();
			$("#verify-input").hide();
			function deselect() {
				$(".pop").slideFadeToggle(function() {
					$("#signup").removeClass("selected");
				});
			}

			$(function() {
				$("#signup").live('click', function() {
					if ($(this).hasClass("selected")) {
						deselect();
					} else {
						$(this).addClass("selected");
						$(".pop").slideFadeToggle(function() {
							showLabels();
						});
					}
					return false;
				});
				
				$("#signuplink").live('click', function() {
					if ($(this).hasClass("selected")) {
						deselect();
					} else {
						$(this).addClass("selected");
						$(".pop").slideFadeToggle(function() {
							showLabels();
						});
					}
					return false;
				});


				$(".close").live('click', function() {
					deselect();
					return false;
				});
			});

			$.fn.slideFadeToggle = function(easing, callback) {
				return this.animate({
					opacity : 'toggle',
					height : 'toggle'
				}, "fast", easing, callback);
			};

			function showLabels() {
				var email = $("#email-input");
				email.attr('value', 'email');
				email.focusin(function() {
					if (email.attr('value') === 'email') {
						email.attr('value', '');
						$('.email-error-notification').fadeOut('slow', function() {
							$('.email-error-notification').remove();
						});
					}
				});
				email.focusout(function() {
					if (email.attr('value') === '') {
						email.attr('value', 'email');
					}
				});
				;
				var tempPasswordField = $("<input>").attr("type", "text");
				tempPasswordField.val("password");
				var tempVerifyField = $("<input>").attr("type", "text");
				tempVerifyField.val("verify password");
				$("#password-input").hide();
				$("#verify-input").hide();
				tempPasswordField.insertBefore($("#hidden-pinput"));
				tempVerifyField.insertBefore($("#hidden-vinput"));
				$("#hidden-pinput").remove();
				$("#hidden-vinput").remove();
				tempPasswordField.focus(function() {
					tempPasswordField.hide();
					$("#password-input").show();
					$("#password-input").focus();
					$('.password-error-notification').fadeOut('slow', function() {
						$('.password-error-notification').remove();
					});
				});
				tempVerifyField.focus(function() {
					tempVerifyField.hide();
					$("#verify-input").show();
					$("#verify-input").focus();
					$('.verify-error-notification').fadeOut('slow', function() {
						$('.verify-error-notification').remove();
					});
				});
				$("#password-input").blur(function() {
					if ($(this).val() === "") {
						tempPasswordField.show();
						tempPasswordField.val("password");
						$(this).hide();
					}
				});
				$("#verify-input").blur(function() {
					if ($(this).val() === "") {
						tempVerifyField.show();
						tempVerifyField.val("verify password");
						$(this).hide();
					}
				});
			}

			$("form").submit(
					function(e) {
						if ($("#email-input").val() === '' || $("#email-input").val() === 'email') {
							$('.email-error-notification').remove();
							var $err = $('<div>').addClass(
							'email-error-notification').html(
							'email is required').css('left',
									$("#email-input").position().right);
							$(this).after($err);
							$err.fadeIn('fast');
							$("#email-input").blur();
							return false;
						}
						 if ($("#password-input").val() === '') {
							$('.password-error-notification').remove();
							var $err = $('<div>').addClass(
							'password-error-notification').html(
							'password is required').css('left',
									$("#password-input").position().right);
							$(this).after($err);
							$err.fadeIn('fast');
							return false;
						}
						if ($("#verify-input").val() === '') {
							e.preventDefault();
							$('.verify-error-notification').remove();
							var $err1 = $('<div').addClass(
							'verify-error-notification').html(
							'please re-enter password').css('left',
									$("#verify-input").position().right);
							$(this).after($err1);
							$err1.fadeIn('fast');
							
						}
												
					});
			

		});
/* $("#formSubmit").live('click', function(){ */

$('.email-error-notification').live('click', function() {
	$(this).fadeOut('slow', function() {
		$(this).remove();
	});
});

$('.password-error-notification').live('click', function() {
	$(this).fadeOut('slow', function() {
		$(this).remove();
	});
});

$('.verify-error-notification').live('click', function() {
	$(this).fadeOut('slow', function() {
		$(this).remove();
	});
});
